package edu.egypt.rawfileresource;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class RawfileResourceSampleActivity extends Activity {
    private EditText editText;
	private Button button;

	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        editText = (EditText)findViewById(R.id.editText1);
        button = (Button)findViewById(R.id.button1);
        button.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				InputStream inputStream = getResources().openRawResource(R.raw.egemen);
				BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
				String str = null;
				
				try {
					while( (str = br.readLine()) != null){
						editText.append(str+"\n");
					}
					inputStream.close();
					br.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
				
			}
		});
    }
}